import { useStore } from "vuex";

// 下一曲和上一曲
export default function () {
    const store = useStore();
    function nextSong(value) {
        //  当播放列表不等于空时,在执行.
        if (store.state.SongList.songlist !== null) {
            const songlist = store.state.SongList.songlist;
            const songid = store.state.PlaySong.presentSong.SongId;
            for (let index = 0; index < songlist.length; index++) {

                if (songlist[index].id === songid) {

                    if (songlist.length - 1 === index) {
                        index = 0;
                    } else if (index === 0) {
                        index = songlist.length - 1;
                    } else {
                        index = index + value;
                    }

                    store.dispatch("PlaySong/playSong", { SongId: songlist[index].id, SongTime: songlist[index].duration });
                    store.dispatch("SongLyric/Lyric", songlist[index].id);
                    break;
                }

            }

        }

    }
    return {
        nextSong
    }
}